//
//  NoticeListCell.m
//  Base_App
//
//  Created by Yutian Duan on 2019/5/29.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "NoticeListCell.h"

@implementation NoticeListCell

- (void)awakeFromNib {
  [super awakeFromNib];
  // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
  
  // Configure the view for the selected state
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
  NoticeListCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([self class])];
  if (cell == nil) {
    cell = [[NoticeListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([self class])];
  }
  return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
    [self setupViews];
    
  }
  return self;
}

- (void)setupViews {
  
  CGFloat leftOffset = 30;
  CGFloat fontOffset = 0;
  CGFloat timeW = 90;
  if (IS_IPHONE5) {
    leftOffset = 15;
    fontOffset = 2;
    timeW = 80;
  }

  
  _titleLabel = [[UILabel alloc] init];
  _titleLabel.textColor = [UIColor blackColor];
  _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f - fontOffset];
  [self.contentView addSubview:_titleLabel];
  
  _describeLabel = [[UILabel alloc] init];
  _describeLabel.textColor = [UIColor blackColor];
  _describeLabel.font = [UIFont systemFontOfSize:12.0f - fontOffset];
  _describeLabel.numberOfLines = 2;
  _describeLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  [self.contentView addSubview:_describeLabel];
  
  //!
  _timeLabel = [[UILabel alloc] init];
  _timeLabel.textColor = DEF_GRAY;
  _timeLabel.font = [UIFont systemFontOfSize:12.0f - fontOffset];
  _timeLabel.textAlignment = NSTextAlignmentRight;
  [self.contentView addSubview:_timeLabel];
  
  
  ///!
  _redImageView = [[UIImageView alloc] init];
  _redImageView.image = [UIImage imageNamed:@"Notice_point"];
  [self.contentView addSubview:_redImageView];
  
  _pointImageView = [[UIImageView alloc] init];
//  _pointImageView.backgroundColor = [UIColor orangeColor];
  [self.contentView addSubview:_pointImageView];
  
  
  
  [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.mas_equalTo(self.contentView.mas_leading).offset(leftOffset);
    make.top.mas_equalTo(self.contentView.mas_top).offset(20);
    make.trailing.mas_equalTo(self.timeLabel.mas_leading).offset(-8);
//    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-100);
    make.height.mas_equalTo(@30);
  }];
  
  [_describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.leading.trailing.mas_equalTo(self.titleLabel);
    make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(10);
    make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(-20);
  }];
  
  [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    make.height.mas_equalTo(@20);
    make.trailing.mas_equalTo(self.redImageView.mas_leading).offset(10);
    make.centerY.mas_equalTo(self.titleLabel.mas_centerY);
    make.width.mas_equalTo(@(timeW));
  }];
  
  [_pointImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.trailing.mas_equalTo(self.timeLabel.mas_trailing);
    make.centerY.mas_equalTo(self.describeLabel.mas_centerY);
    make.width.mas_equalTo(@50);
    make.height.mas_equalTo(@12);
  }];
  
  [_redImageView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.trailing.mas_equalTo(self.contentView.mas_trailing).offset(-10);
    make.top.mas_equalTo(self.contentView.mas_top).offset(10);
    make.size.mas_equalTo(CGSizeMake(8, 8));
  }];
  
  
  
}


- (void)setModel:(NoticeListModel *)model {
  _model = model;
  
  [self setupModel];
}

- (void)setupModel {
  
  self.titleLabel.text = @"【油咭】 5月 Caltex 限时折扣大激赏";
  self.describeLabel.text = @"加德士1，加德士2，加德士3，加德士4，加德士5，加德士6，加德士7，加德士8，加德士9，加德士10，加德士11，加德士12，加德士13，加德士14，加德士15，加德士16";
  self.timeLabel.text = @"2019年4月2日";
  
}

@end

